package com.zrar.ak.gkpt.controller.manage;

import com.zrar.ak.gkpt.model.vo.UserVO;
import com.zrar.ak.gkpt.service.manage.IManageUnitInfoService;
import com.zrar.ak.gkpt.service.user.IUserService;
import com.zrar.ak.gkpt.util.FormDataParameter;
import com.zrar.ak.gkpt.util.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @ClassName: ManageUnitInfoController
 * @Description 单位管理Controller层
 * @Author liyang
 * @Time 2020/03/09
 */
@RestController
@RequestMapping("/unit")
@Api(tags = "单位管理相关接口")
@Slf4j   //该注解可以进行日志输出  log
public class ManageUnitInfoController {

    @Autowired
    private IManageUnitInfoService manageUnitInfoService;
    @Autowired
    private IUserService userService;


    @RequestMapping(value = "getLowerUnitAccountInfoList", method = RequestMethod.GET, produces = {"application/json; charset=utf-8"})
    @ApiOperation(value = "获取下级单位信息集合(包括台账录入情况)-条件查询", httpMethod = "GET", notes = "获取下级单位信息集合(包括台账录入情况)-条件查询")
    public JsonResult getLowerUnitAccountInfoList(HttpServletRequest request,
                                                  @ApiParam(name = "unitName", value = "单位名称(模糊查询)") @RequestParam(value = "unitName",required=false) String unitName){
        JsonResult jsonResult = new JsonResult();
        jsonResult = manageUnitInfoService.getLowerUnitAccountInfoList(jsonResult, unitName);
        return jsonResult;
    }


    @RequestMapping(value = "getLowerUnitRecordInfoList", method = RequestMethod.GET, produces = {"application/json; charset=utf-8"})
    @ApiOperation(value = "获取下级单位信息集合(包括备案录入情况)-条件查询", httpMethod = "GET", notes = "获取下级单位信息集合(包括备案录入情况)-条件查询")
    public JsonResult getLowerUnitRecordInfoList(HttpServletRequest request,
                                                  @ApiParam(name = "unitName", value = "单位名称(模糊查询)") @RequestParam(value = "unitName",required=false) String unitName){
        JsonResult jsonResult = new JsonResult();
        jsonResult = manageUnitInfoService.getLowerUnitRecordInfoList(jsonResult, unitName);
        return jsonResult;
    }




    @RequestMapping(value = "dataEdit", method = RequestMethod.POST, produces = {"application/json; charset=utf-8"})
    @ApiOperation(value = "单位信息编辑(新增修改或删除)", httpMethod = "POST", notes = "单位信息编辑(新增修改或删除)")
    public JsonResult dataEdit(HttpServletRequest request,
                                           @ApiParam(name = "formDataParameter", value = "单位信息编辑(新增修改或删除)数据参数") @RequestBody FormDataParameter formDataParameter){
        JsonResult jsonResult = new JsonResult();
        String formDataJson = formDataParameter.getFormDataJson();
        UserVO userVO = userService.getUserInformation(request);
        jsonResult = manageUnitInfoService.dataEdit(jsonResult, formDataJson, userVO);
        return jsonResult;
    }

    @RequestMapping(value = "dataGet", method = RequestMethod.GET, produces = {"application/json; charset=utf-8"})
    @ApiOperation(value = "单位信息获取", httpMethod = "GET", notes = "单位信息获取")
    public JsonResult dataGet(HttpServletRequest request,
                                                  @ApiParam(name = "unitId", value = "单位id") @RequestParam(value = "unitId",required=false) String unitId){
        JsonResult jsonResult = new JsonResult();
        jsonResult = manageUnitInfoService.dataGet(jsonResult, unitId);
        return jsonResult;
    }


}
